// pages/mine/xiyu_record/xiyu_record.js
const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    records: [],
    totalPoints: 10,
    loading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.loadPointsRecords();
  },

  /**
   * 加载积分记录
   */
  loadPointsRecords() {
    // 模拟数据，实际项目中应该从服务器获取
    // const mockData = [
    //   { id: 1, title: '实名认证', date: '2025.04.11', points: 10, type: 'add' },
    //   { id: 2, title: '活动取消补偿', date: '2025.04.11', points: 1, type: 'add' },
    //   { id: 3, title: '报名活动', date: '2025.04.11', points: 1, type: 'minus' },
    //   { id: 4, title: '临时取消报名', date: '2025.04.11', points: 1, type: 'minus' },
    //   { id: 5, title: '临时取消活动', date: '2025.04.11', points: 5, type: 'minus' },
    //   { id: 6, title: '成功发布活动', date: '2025.04.11', points: 5, type: 'add' }
    // ];
    
    // 计算总积分
    // let total = 0;
    // mockData.forEach(item => {
    //   if (item.type === 'add') {
    //     total += item.points;
    //   } else {
    //     total -= item.points;
    //   }
    // });
    
    // setTimeout(() => {
    //   this.setData({
    //     records: mockData,
    //     totalPoints: total,
    //     loading: false
    //   });
    // }, 500);
    
    // 实际项目中的API调用示例
    /*
    wx.request({
      url: app.globalData.onlineService + '/api/points/records',
      method: 'GET',
      header: {
        'content-type': 'application/json',
        'Authorization': `Bearer ${app.globalData.userInfo.token}`
      },
      success: (res) => {
        if (res.data.code === 200) {
          this.setData({
            records: res.data.data.list,
            totalPoints: res.data.data.total,
            loading: false
          });
        } else {
          wx.showToast({
            title: res.data.msg || '获取积分记录失败',
            icon: 'none'
          });
          this.setData({ loading: false });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        });
        this.setData({ loading: false });
      }
    });
    */
  },

  /**
   * 下拉刷新
   */
  onPullDownRefresh() {
    this.setData({ loading: true });
    this.loadPointsRecords();
    wx.stopPullDownRefresh();
  }
})